#ifndef _UTILS_AMANAGER_H_
# define _UTILS_AMANAGER_H_

# include "config.h"
# include <map>
# include <list>
# include <string>
# include "Utils\\IArgs.h"

NS_BEGIN(SDL)
	NS_BEGIN(UTILS)

	template<typename T>
	class AManager
	{
	public:
		struct Element;
		typedef typename bool (*MngrFunc)(Element*, IArgs*);
	public:
		struct Element
		{
			T*			Object;
			IArgs*		Datas;
			bool		Delete;

			Element(T* _object, IArgs* _datas, bool _delete = false);
			~Element();
		};
	protected:
		typedef std::pair<Element*, MngrFunc> Pair;
		typedef typename std::map< std::string, Pair> Elements;
		Elements m_elements;

	protected:
		AManager();
	private:
		AManager(AManager const&);
	protected:
		virtual ~AManager();

	private:
		AManager& operator=(AManager const&);
	public:
		T* operator[](std::string const& _name);

		virtual void Add(std::string const& _name, T* _element,
						 MngrFunc _func = NULL, IArgs* _datas = NULL,
						 bool _delete = true);
		virtual void Remove(std::string const& _name);
		virtual void Clear();
		virtual void Manage(IArgs*) = 0;
		void GetElements(std::list<Element*>& _out);
		Element* GetElement(std::string const& _name);
	};

	NS_END(UTILS)
NS_END(SDL)

# include "Utils\\AManager.tpp"

#endif // _UTILS_AMANAGER_H_